#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>

using namespace std;
#define LL long long
const LL maxn = 110;
LL k = 0;

LL C[maxn];
LL E[maxn];
LL D;
char s[100010];

bool isLL(char c)
{
	if (c >= '0' && c <= '9')
		return true;
	return false;
}

void input()
{

	memset(E, 0, sizeof(E));
	for (LL i = 0; i < maxn; i++)
		C[i] = 1;

	k = -1;
	bool ispos = 1;
	LL i = 1;
	while (s[i] != ')')
	{
		k++;
		if (s[i] == '-')
		{
			ispos = 0;
			i++;
		} else if (s[i] == '+')
			i++;
		if (isLL(s[i]))
		{
			C[k] = s[i] - '0';
			i++;
			while (isLL(s[i]))
			{
				C[k] = C[k] * 10 + (s[i] - '0');
				i++;
			}
		}
		if (s[i] == 'n')
		{
			i++;
			if (s[i] == '^')
			{
				i++;
				E[k] = (s[i] - '0');
				i++;
				while (isLL(s[i]))
				{
					E[k] = E[k] * 10 + (s[i] - '0');
					i++;
				}
			} else
				E[k] = 1;
		} else
		{
			E[k] = 0;
		}
		if (!ispos)
		{
			C[k] = -C[k];
			ispos = 1;
		}
	}
	i += 2;
	int ff=1;
	if(s[i]=='-'){i++;ff=-1;}
	D = s[i]-'0';
	i++;
	while (isLL(s[i]))
	{
		D = D * 10 + (s[i] - '0');
		i++;
	}
	D=D*ff;

}

LL quick_mod(LL a, LL b, LL m)
{
	LL ans = 1;
	while (b)
	{
		if (b & 1)
		{
			ans = (ans * a) % m;
		}
		b >>= 1;
		a = (a * a) % m;
	}

	return ((ans+m)%m);
}

int main()
{
	char c;
	int cas = 1;
	while (cin>>s)
	{
		if(s[0]=='.')break;
		input();
		bool jj = 1;
		for (LL i = 1; i <= 101; i++)
		{
			LL ans = 0;
			for (LL j = 0; j <= k; j++)
			{
				ans += (C[j] * quick_mod(i, E[j], D))%D;
			}
			if (ans % D != 0)
			{
				jj = false;
				break;
			}
		}

		if (jj)
			printf("Case %d: Always an integer\n", cas++);
		else
			printf("Case %d: Not always an integer\n", cas++);

	}
	return 0;
}
